package com.toss.single;

import io.vertx.core.Vertx;
import io.vertx.core.http.HttpServer;

public class VertxWebsocket {
	public static void main(String[] args) {
		Vertx vertx = Vertx.vertx();
		HttpServer httpServer = vertx.createHttpServer();
		httpServer.websocketHandler(webSocket -> {
			if (!webSocket.uri().equals("/ws")) {
				webSocket.reject();
				return;
			}
			webSocket.writeFinalTextFrame("Hello Vert.x webSocket");
			webSocket.frameHandler(webSocketFrame -> {
				String msg = webSocketFrame.textData();
				webSocket.writeFinalTextFrame("Vert.x recieve message:" + msg);
			});
			System.out.println("webSocket connected");
			webSocket.closeHandler(closeHandler -> {
				System.out.println("webSocket disconnect");
			});
		});
		httpServer.listen(8080);
	}
}
